﻿
module("Earth")
test("Earth init", function () {
    var width = 10;
    var height = 20;
    var earth = new tetris.Earth(width, height);

    equal(10, earth.width, "Earth width is set");
    equal(20, earth.height, "Earth height is set");

    var body = "";
    for (var i = 0; i < earth.getBody.length; i++) {
        body += earth.getBody[i].coordinate.toString() + " ";
    }
    equal("", body, "CenterY of FallingJ is set");
});

test("Earth with square", function () {
    var width = 10;
    var height = 20;
    var earth = new tetris.Earth(width, height);

    equal(10, earth.width, "Earth width is set");
    equal(20, earth.height, "Earth height is set");

    var color = "#FF0000";
    var sq = new tetris.FallingSquare(0, 0, color);
    sq.moveTo(2, 6);
    earth.add(sq);
    var body = "";
    for (var i = 0; i < earth.getBody.length; i++) {
        body += earth.getBody[i].coordinate.toString() + " ";
    }
    equal("(2,6) (3,6) (2,7) (3,7) ", body, "Square addad to earth");

    var rows = earth.updateBodyAndReturnCollapsedRowsCount(); 
    equal(0, rows, "Square addad to earth");

    for (var i = 0; i < earth.getBody.length; i++) {
        body += earth.getBody[i].coordinate.toString() + " ";
    }
    equal("(2,6) (3,6) (2,7) (3,7) (2,6) (3,6) (2,7) (3,7) ", body, "Square addad to earth");
});

test("Is in range", function () {
    var x = 10;
    var y = 20;
    var earth = new tetris.Earth(30, 40);
    var isIn=earth.isInRange(x,y)
    ok(isIn, "The point is in range");
});

test("Earth contains (x,y)", function () {
    var width = 10;
    var height = 20;
    var earth = new tetris.Earth(width, height);

    var color = "#FF0000";
    var sq = new tetris.FallingL(0, 0, color);
    sq.moveTo(2, 6);
    earth.add(sq);

    var body = "";
    for (var i = 0; i < earth.getBody.length; i++) {
        body += earth.getBody[i].coordinate.toString() + " ";
    }
    equal("(2,5) (2,6) (2,7) (3,7) ", body, "Square addad to earth");

    var isContains = earth.contains(2, 6);
    ok(isContains, "The earth contains this point");
    ok(!(earth.contains(3, 6)), "The earth contains this point");
});
